#include "SceneNodes.h"
/////////////////////////////////////////////////////
////
//// Scene Node Related Stuff
////
bool SceneNode::VAddChild(SceneNodePtr scene_node)
{
	m_Children.push_back(scene_node);
	return true;
}
SceneNodeList& SceneNode::VGetChildren()
{
	return m_Children;
}

bool SceneNode::VOnRender(IScene *pScene)
{
	//Some Fancy Drawing Code Here; Or at least in the inherited classes

	return SceneNode::VRenderChildren(pScene);
}

bool SceneNode::VPreRender(IScene *pScene)
{
	//get the world matrix and push it into scene's matrix stack
	pScene->VPushAndSetMatrix(m_Props.m_ToWorld);
	return true;
}

bool SceneNode::VPostRender(IScene *pScene)
{
	//pop the last matrix pushed into the stack
	pScene->VPopMatrix();
	return true;
}

bool SceneNode::VRenderChildren(IScene *pScene)
{
	if(m_Children.size() > 0)
	{
		SceneNodeList::iterator begin = m_Children.begin();
		SceneNodeList::iterator end = m_Children.end();
		while(begin != end)
		{
			if((*begin)->VIsVisible() == true)
			{
				if((*begin)->VPreRender(pScene))
				{
					(*begin)->VOnRender(pScene);
					(*begin)->VPostRender(pScene);
				} else {
				return false;
				}
			}
			begin++;
		}
	}
	return true;
}

bool SceneNode::VUpdateChildren(float fTime)
{
		if(m_Children.size() > 0)
	{
		SceneNodeList::iterator begin = m_Children.begin();
		SceneNodeList::iterator end = m_Children.end();
		while(begin != end)
		{
			if((*begin)->VIsVisible() == true)
			{
				if(!(*begin)->VOnUpdate(fTime))
				return false;
			}
			begin++;
		}
	}
		return true;
}

bool SceneNode::VIsVisible()
{
	return m_IsVisible;
}




ActorId SceneNode::VGetId()
{
	return m_Props.m_ActorId;
}


